// 队列遵循先进先出原则fifo
class Queue {
  constructor() {
    this.count = 0; // {1} 
    this.lowestCount = 0; // {2} 
    this.items = {}; // {3} 
  }
  enqueue(ele) {
    this.items[this.count] = ele;
    this.count++;
  }
  dequeue() {
    if (this.isEmpty()) {
      return undefined
    }
    let result = this.items[this.lowestCount];
    delete this.items[this.lowestCount];
    this.lowestCount++
    return result
  }
  peek() {
    if (this.isEmpty()) {
      return undefined
    }
    return this.items[this.lowestCount]
  }
  isEmpty() {
    return this.count - this.lowestCount === 0
  }
  size() {
    return this.count - this.lowestCount
  }
  clear() {
    this.count = 0;
    this.lowestCount = 0
    this.items = {}
  }
  toString() {
    if (this.isEmpty()) {
      return ''
    }
    let objectStr = this.items[this.lowestCount];
    for (let i = this.lowestCount + 1; i < this.count; i++) {
      objectStr = `${objectStr},${this.items[i]}`
    }
    return objectStr
  }
}

let queue = new Queue()
queue.enqueue('a')
queue.enqueue('b')
queue.enqueue('c')
console.log(queue.toString())
console.log(queue.peek())
queue.dequeue()
queue.dequeue()
console.log(queue.toString())